package com.androidserver.server;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.androidserver.util.DatastoreWrapper;
import com.google.appengine.api.datastore.Entity;

@SuppressWarnings("serial")
public class AddToGroup extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {
		
		if (!req.getHeader("User-Agent").contains("Android")) {
			resp.getWriter().print("No browser access");
			return;
		}
		DatastoreWrapper dataWrapper = DatastoreWrapper.getInstance();
		Entity member = dataWrapper.getMemberByID(req.getParameter("idCode"));
		boolean result = false;
		if (member != null) {
			result = dataWrapper.addMemberToGroup(member, req.getParameter("groupName"));
		} else {
			resp.getWriter().print("WRONG_MEMBER");
			return;
		}
		if (result) {
			resp.getWriter().print("OK");
		} else {
			resp.getWriter().print("FAIL");
		}
		
	}
}
